# module aem.timer -- Classes for space and time time-varying values

import copy

class TValue:
	"""
	Base class for Time varying values to be used, e.g. as setpoints.
	A "function object" that returns a vector of values (as a numpy array) as a
	function of space and time.
	"""
	def __call__(self,t=0):
		raise "Must override aem.TValue.__call__()"


class ConstantTValue(TValue):
	"""
	An TValue derived class that returns a constant value for all time.
	"""
	def __init__(self,vvalue):
		self.vvalue = copy.copy(vvalue)
	def __call__(self,t=0):
		return self.vvalue

class StepTValue(TValue):
	"""
	A TValue that "steps" at specified times.  Constructor recieves a list of (t,value)
	tuples.
	"""
	def __init__(self,vvalues):
		self.vvalueList = copy.copy(vvalues)
	def __call__(self,t=0):
		if self.vvalueList[0][0] > t: raise "Time out of range"
		for i in self.vvalueList:
			if t < i[0]: return iprev[1]
			else: iprev = i
		return iprev[1]

class STValue:
	"""
	Base class for Space-Time varying values to be used, e.g. as setpoints.
	A "function object" that returns a vector of values (as a numpy array) as a
	function of space and time.
	"""
	def __call__(self,x=0,y=0,z=0,t=0):
		raise "Must override aem.STValue.__call__()"


class ConstantSTValue(STValue):
	"""
	An STValue derived class that returns a constant value for all points and all time;
	returns the same (vector) value, as a numpy array for all space and time.
	"""
	def __init__(self,vvalue):
		self.vvalue = vvalue
	def __call__(self,x=0,y=0,z=0,t=0):
		return self.vvalue
